#include <interface\fieldset.h>
#include <interface\gl.h>

#include <interface\window.h>

fieldSet::fieldSet():   winElmt(){
    ELname = "<fieldSet>";
}
fieldSet::fieldSet(window* win):    winElmt( win ){
    ELname = "<fieldSet>";
    parentWin->addToElmts(this);
}
fieldSet::~fieldSet(){
    if( !parentWin ) return;
    parentWin->remFromElmts(this);
}

void fieldSet::clipToWindow(){
    if( !parentWin ) return;
    setRect(0,0,parentWin->getCurWidth(),parentWin->getCurHeight());
}

void fieldSet::setParentWin(window* wd){
    winElmt::setParentWin(wd);
    parentWin->addToElmts(this);
}

void fieldSet::display(){
    if( !styleS ) return;
    winElmt::display();
    glDisable(GL_SCISSOR_TEST);
    int Xoff = 0;
    int Yoff = 0;
    getOffset(&Xoff,&Yoff);
    glColor(bkgColFromSS(elm_fieldset));
    glDrawRect(enc,Xoff,Yoff);
    elDraw();
}
void fieldSet::elDraw(){
    int Xoff = 0;
    int Yoff = 0;
    getOffset(&Xoff,&Yoff);
    glSetRenderArea(enc,Xoff,Yoff);
    weCtr::elDraw();
}
unsigned char fieldSet::eventExec(unsigned char in){
    if( !parentWin ) return in;
    in = weCtr::elEventExec(in);
    in = winElmt::eventExec(in);
    return in;
}

void fieldSet::activeGetEvent(){
    winElmt::activeGetEvent();
    for( vector<winElmt*>::iterator i = elements.begin(); i < elements.end(); i++ ){
        if( (*i)->isActive() ) (*i)->activeLoseEvent();
    }
}
